package com.feihong.yw189.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.text.method.ScrollingMovementMethod;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.feihong.yw189.R;
import com.feihong.yw189.model.notice.NoticeInfo;

/**
 * @Author wangziheng
 * @ProjectName ywydt
 * @ClassName NoticeDialog
 * @package com.feihong.yw189.dialog
 * @data 2018/11/6 19:32
 * @Describe
 * @Change
 */
public class NoticeDialog extends Dialog {
    private LayoutInflater mLayoutInflater;
    private View view;
    private TextView mNoticeTitleTv,mNoticeContentTv;
    private Context mContext;
    public NoticeDialog(Context context){
        super(context,R.style.MyDefindDialog);
        mLayoutInflater = LayoutInflater.from(context);
        mContext = context;
        initview();
    }

    private void initview() {
        view = mLayoutInflater.inflate(R.layout.notice_dialog_layout,null);
        setContentView(view);
        mNoticeTitleTv = view.findViewById(R.id.home_notice_title_tv);
        mNoticeContentTv = view.findViewById(R.id.home_notice_content_tv);
        mNoticeContentTv.setMovementMethod(ScrollingMovementMethod.getInstance());
        setCanceledOnTouchOutside(true);
        setCancelable(true);
    }

    public void setContent(NoticeInfo.DataBean info){

        String htmlTxt = info.getContent();
        Spanned tvTxt = Html.fromHtml(htmlTxt);

        mNoticeContentTv.setText(tvTxt);
        mNoticeTitleTv.setText(info.getTitle());
    }
    public void showDialog(){
        show();
        WindowManager windowManager = ((Activity) mContext).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = display.getWidth();
        getWindow().setAttributes(lp);
    }
}
